package com.lyn.android_custom_view;

import android.view.View;
import com.lyn.android_custom_view.databinding.ActivityCartogramBinding;
import com.lyn.module_custom_base.avtivity.BaseActivity;
import com.lyn.module_custom_view.pieChart.entity.ChartCircleItem;
import com.lyn.module_custom_view.pieChart.entity.ChartHistogramItem;
import com.lyn.module_custom_view.pieChart.entity.ChartLineItem;

import java.util.ArrayList;
import java.util.Random;

/**
 * created by lyn at 2021/10/23
 */
public class CartoGramActivity extends BaseActivity<ActivityCartogramBinding> {
    @Override
    public ActivityCartogramBinding getBinding() {
        return ActivityCartogramBinding.inflate(getLayoutInflater());
    }

    @Override
    public void setBinding(ActivityCartogramBinding binding) {
        binding.toolbar.title.setText("统计图");
        initChartLineData();
        initChartCircleData();
        initChartHistogramData();
    }

    @Override
    public void setListener(ActivityCartogramBinding binding) {
        binding.toolbar.back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                changeUI(MainActivity.class);
                finish();
            }
        });

    }

    @Override
    public boolean onBack() {
        return true;
    }

    public void initChartLineData() {
        //横坐标titles数据
        ArrayList<String> axesTitles = new ArrayList<>();
        for (int i = 2; i <= 12; i++) {
            axesTitles.add(i + "");
        }

        //设置横坐标titles
        binding.chartLine.setHoriItems(axesTitles);


        ArrayList<ChartLineItem> items = new ArrayList<>();

        /*
         * 参数：
         * 1、折线统计的数据源
         * 2、此折线的颜色值
         * 3、手势操作后，展示此折线数据的描述语
         * 4、此折线是否带阴影填充色
         * 5、此折线是否带动画展示
         * */
        ArrayList<Integer> points = new ArrayList<>();
        for (int i = 0; i < 12; i++) {
            points.add(new Random().nextInt(100));
        }
        ArrayList<Integer> points2 = new ArrayList<>();
        for (int i = 0; i < 12; i++) {
            points2.add(new Random().nextInt(100));
        }
        items.add(new ChartLineItem(points, R.color.colorRed, "昨日", true, true));
        items.add(new ChartLineItem(points2, R.color.colorBlack, "今日", true, true));
        //设置折线数据源
        binding.chartLine.setItems(items);
    }


    private void initChartCircleData() {
        ArrayList<ChartCircleItem> items = new ArrayList<>();
        items.add(new ChartCircleItem(3, R.color.colorYellow, "原价"));
        items.add(new ChartCircleItem(2, R.color.colorBlue, "优惠"));
        items.add(new ChartCircleItem(4, R.color.colorBlack, "辣鸡"));
        items.add(new ChartCircleItem(1, R.color.colorRed, "很棒"));

        binding.chartCircle.setItems(items);
    }

    private void initChartHistogramData(){
        ArrayList<ChartHistogramItem> items = new ArrayList<>();
        items.add(new ChartHistogramItem(30, R.color.colorBlue, "推理", true));
        items.add(new ChartHistogramItem(50, R.color.colorBlue, "记忆", true));
        items.add(new ChartHistogramItem(90, R.color.colorBlue, "视觉", true));
        items.add(new ChartHistogramItem(80, R.color.colorBlue, "反应", true));
        binding.chartHistogram.setItems(items);
    }
}
